//
//  YZWelcomeController.m
//  优品美妆
//
//  Created by apple on 15/8/28.
//  Copyright (c) 2015年 RongChunagYin. All rights reserved.
//

#import "YZWelcomeController.h"
#import "AppDelegate.h"


@interface YZWelcomeController ()<UIScrollViewDelegate>
@property (strong, nonatomic) UIScrollView * scroll;
//体验按钮
@property (strong, nonatomic) UIButton * enterButton;
@property (strong, nonatomic) UIPageControl *pageControl;
@end
#define WIDTH [[UIScreen mainScreen]bounds].size.width
#define HEIGHT [[UIScreen mainScreen]bounds].size.height
@implementation YZWelcomeController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self prefersStatusBarHidden];
    UIScrollView * scrollView=[[UIScrollView alloc]initWithFrame:self.view.frame];
    self.scroll=scrollView;
    
    scrollView.frame = CGRectMake(0, 0, WIDTH, HEIGHT);
    scrollView.userInteractionEnabled = YES;
    scrollView.showsHorizontalScrollIndicator = NO;
    scrollView.showsVerticalScrollIndicator = NO;
    scrollView.contentSize = CGSizeMake(WIDTH * 5, HEIGHT);
    scrollView.pagingEnabled = YES;
    
    //添加欢迎图片
    for (int i = 0 ; i < 5; i++) {
        UIImageView * imageView = [[UIImageView alloc]initWithFrame:CGRectMake(WIDTH * i, 0, WIDTH, HEIGHT)];
        
        if(HEIGHT<568){
        imageView.image = [UIImage imageNamed:[NSString stringWithFormat:@"4D%d.png",i+1]];
            
        }else if (HEIGHT == 568){
        imageView.image = [UIImage imageNamed:[NSString stringWithFormat:@"5D%d.png",i+1]];
            
        }else if (HEIGHT == 667){
        imageView.image = [UIImage imageNamed:[NSString stringWithFormat:@"6D%d.png",i+1]];
        }else if (HEIGHT >667){
        imageView.image = [UIImage imageNamed:[NSString stringWithFormat:@"6PD%d.png",i+1]];
        }
        [scrollView addSubview:imageView];
        
        //添加跳过按钮
        UIButton *jumpBtn = [[UIButton alloc] init];
        jumpBtn.frame = CGRectMake(scrollView.contentSize.width - WIDTH * 0.2 - 10, HEIGHT - 60, WIDTH * 0.2, 60);
        [jumpBtn addTarget:self action:@selector(jump) forControlEvents:UIControlEventTouchUpInside];
        jumpBtn.titleLabel.font = [UIFont systemFontOfSize:17.f];
        [jumpBtn setTitle:@"跳过" forState:0];
        [jumpBtn setTitleColor:[UIColor redColor] forState:0];
//        jumpBtn.backgroundColor = [UIColor orangeColor];
        [scrollView addSubview:jumpBtn];
        
    }

    scrollView.delegate = self;
    
    //配置分页空间UIpageControl
    UIPageControl*pageControl=[[UIPageControl alloc]init];
    self.pageControl=pageControl;
    //配置
    pageControl.frame=CGRectMake(0, HEIGHT-70, WIDTH, 30);
    //配置圆点个数
    pageControl.numberOfPages=5;
    //配置圆点颜色
    pageControl.pageIndicatorTintColor=[UIColor whiteColor];
    //配置当前页面圆点颜色
    pageControl.currentPageIndicatorTintColor=[UIColor orangeColor];
    //关闭用户交互功能
    pageControl.enabled=NO;

    [self.view addSubview:scrollView];
    //添加到self.view
    [self.view addSubview:pageControl];
}

//当滚动视图发生滚动时,执行该方法
- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
    //项知道到底这个滚动视图位置在哪
    CGPoint Point=scrollView.contentOffset;
    NSInteger index=round(Point.x/scrollView.frame.size.width);
    self.pageControl.currentPage=index;
    
}

-(void)jump{
    
    UIStoryboard *LoginAndRegister = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
    UINavigationController *loginNAV = [LoginAndRegister instantiateViewControllerWithIdentifier:@"LoginNav"];
    
    [self presentViewController:loginNAV animated:YES completion:nil];
}




@end
